define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vppz/zl_order/index' + location.search,
                    //add_url: 'vppz/order/add',
                    //edit_url: 'vppz/order/edit',
                    //del_url: 'vppz/order/del',
                    multi_url: 'vppz/zl_order/multi',
                    import_url: 'vppz/zl_order/import',
                    table: 'vppz_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                //fixedColumns: true,
                //fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
						{field: 'num', title: '订单号', operate: 'LIKE'},
						{field: 'title', title: '订单标题', operate: 'LIKE',visible: false},
                        //{field: 'service_id', title: __('Service_id')},
						{field: 'service_logo_image', title: '设备', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
						{field: 'service_name', title: '设备名称', operate: 'LIKE'},
                        {field: 'service_stype', title: __('Service_stype'), searchList: {"10":__('Service_stype 10'),"15":__('Service_stype 15'),"20":__('Service_stype 20'),"30":__('Service_stype 30'),"40":__('Service_stype 40'),"110":__('Service_stype 110'),"210":__('Service_stype 210')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'saletype_name', title: '类型', operate: 'LIKE', searchList: {"rent":__('Rent'),"sale":__('Sale')}, formatter: Table.api.formatter.normal},


						{field: 'user.avatar', title: '用户', operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image,searchable:false},
						{field: 'user.nickname', title: '用户昵称', operate: 'LIKE'},
						{field: 'tel', title: '联系电话', operate: 'LIKE'},

						{field: 'name', title: '联系人', operate: 'LIKE'},
                        {field: 'openid', title: '用户openid', operate: 'LIKE',visible: false},

                        //{field: 'user_id', title: __('User_id')},

                        {field: 'price', title: __('Price'), operate:'BETWEEN',visible: false,searchable:false},
                        {field: 'cnt', title: __('Cnt'),visible: false,searchable:false},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'cut', title: __('Cut'), operate:'BETWEEN',visible: false,searchable:false},
                        {field: 'to_pay', title: '需付', operate:'BETWEEN'},

						{field: 'pay', title: '已付', operate:'BETWEEN'},
						{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
						{field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

						{field: 'status', title: __('Status'), searchList: {"10":__('Status 10'),"20":__('Status 20'),"30":__('Status 30'),"40":__('Status 40')}, formatter: Table.api.formatter.status,custom:{'10':'warning','20':'info','30':'success','40':'muted'}},//"0":__('Status 0'),

                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [{
                                    name: 'staff',
                                    title: '查看',
									text: '查看',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'vppz/zl_order/detail'
                                }]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
